package utils

import (
	"fmt"
	"io"
	"os"
	"path"
	"openapi.itspire.cn/config"
)

func LogFile() (io.Writer, string) {
	// 目录路径
	logDirPath := config.Conf.App.LogDir
	// 文件名
	logFileName := config.Conf.App.AppName
	// 文件路径
	logFilePath := path.Join(logDirPath, logFileName)
	// 获取文件句柄
	//f, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
	//f, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	f ,err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		fmt.Println("Open Src File err", err)
	}
	return f, logFilePath
}

func FileExists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err != nil { return false, err }
	if os.IsNotExist(err) { return false, err }
	return true, err
}
